import { defineStore } from "pinia";
import { computed, ref } from "vue";

export const useUserStore = defineStore("user", () => {
    //定义state - 需要分享的数据
    const user = ref(null);

    //定义getter - 获取state
    const userInfo = computed(() => user.value);

    //重置state
    function updateUser(tk) {
        user.value = tk;
    }


    //定义action - 修改state
    function $reset() {
        user.value = null;
    }

    return {user, userInfo, updateUser, $reset};
},{
    persist: {
        key: 'user',
        storage: sessionStorage,
        paths: ['token']
    }
});